@extends('Admin.layout.layout')
@section('content')
    <div class="wrapper wrapper-content animated fadeInRight">
        <div class="row">
            <div class="col-sm-12">
                <div class="ibox float-e-margins">
                    <div class="ibox-title">
                        <h5>商品订单</h5>
                    </div>
                    <div class="ibox-content">
                        <div class="row">
                            <form action="" method="GET">
                                {{csrf_field()}}
                                <div class="col-sm-12">
                                    <div class="input-group fl mr10">
                                        <input name="order_code" type="text" placeholder="请输入订单编号" class="input-sm form-control" value="{{array_get($search_params, 'order_code')}}">
                                    </div>
                                    <div class="input-group fl mr10">
                                        <input name="user_name" type="text" placeholder="请输入买家账号" class="input-sm form-control" value="{{array_get($search_params, 'user_name')}}">
                                    </div>
                                    <div class="input-group fl mr10">
                                        <input name="shop_name" type="text" placeholder="请输入店铺名称" class="input-sm form-control" value="{{array_get($search_params, 'shop_name')}}">
                                    </div>
                                    <div class="input-group fl mr10">
                                        <input name="trade_no" type="text" placeholder="请输入支付单号" class="input-sm form-control" value="{{array_get($search_params, 'trade_no')}}">
                                    </div>
                                    <div class="input-group fl mr10">
                                        <select    style="float: left; margin-right: 10px;" class="input-sm form-control"  name="order_type"  id="order_type">
                                            <option value="">请选择</option>
                                            <option @if(1 == $search_params['order_type']) selected="selected" @endif value="1">商品订单</option>
                                            <option @if(4 == $search_params['order_type']) selected="selected" @endif value="4">配单订单</option>
                                            <option @if(6 == $search_params['order_type']) selected="selected" @endif value="6">资质订单</option>
                                        </select>
                                    </div>
                                    <div class="input-group fl mr10">
                                        <input name="pay_at[start]" placeholder="开始日期" class="input-sm form-control layer-date" id="start" value="{{array_get($search_params, 'pay_at.start')}}">
                                    </div>
                                    <div class="input-group fl mr10">
                                        <input name="pay_at[end]" placeholder="结束日期" class="input-sm form-control layer-date" id="end" value="{{array_get($search_params, 'pay_at.end')}}">
                                    </div>
                                    <button type="submit" class="btn btn-sm btn-primary fl">查询</button>
                                </div>
                            </form>
                        </div>
                        <table class="table table-striped table-bordered table-hover dataTable" id="editable">
                            <thead>
                                <tr>
                                    <th width="15">
                                        <input type="checkbox" class="checkall" name="selectall" />
                                    </th>
                                    <th>订单ID</th>
                                    <th>下单时间</th>
                                    <th>订单金额(元)</th>
                                    <th>买家名</th>
                                    <th>店铺名</th>
                                    <th class="center">状态</th>
                                    <th class="center">支付单号</th>
                                    <th class="center">操作</th>
                                </tr>
                            </thead>
                            <tbody>
                                @if(!empty($list))
                                    @foreach($list as $order)
                                    <tr class="gradeX">
                                        <th>
                                            <input type="checkbox" class="checkall" name="checkBox[]" value="" />
                                        </th>
                                        <td>{{array_get($order, 'order_code')}}</td>
                                        <td>{{array_get($order, 'created_at')}}</td>
                                        <td>{{array_get($order, 'order_money')}}</td>
                                        <td>{{array_get($order, 'user.name')}}</td>
                                        <td>{{array_get($order, 'shop.sp_name')}}</td>
                                        <td class="center">{{array_get($order, 'order_status_name')}}</td>
                                        <td class="center">{{array_get($order, 'trade_no')}}</td>
                                        <td class="center">
                                            <a class="btn-xs btn-primary check_order" data-id="{{array_get($order, 'id')}}">查看</a>
                                            @if(array_get($order, 'order_status') == 1)
                                                <a class="btn-xs btn-danger cancel_order" data-id="{{array_get($order, 'id')}}">取消订单</a>
                                            @endif
                                        </td>
                                    </tr>
                                    @endforeach
                                @else
                                    <tr class="no-records-found center"><td colspan="9">没有找到匹配的记录</td></tr>
                                @endif
                            </tbody>
                        </table>
                        <div class="row">
                            @include('Admin.common.paginate', ['page' => $page])
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>


    <script src="{{asset('js/plugins/layer/laydate/laydate.js')}}"></script>
    <script src="{{asset('js/plugins/layer/layer.min.js')}}"></script>

    <script>
        var cancel_order = '/foradmin/order/{id}';
        //日期范围限制
        var start = {
            elem: '#start',
            format: 'YYYY-MM-DD hh:mm:ss',
            min: laydate.now(), //设定最小日期为当前日期
            max: '2099-06-16 23:59:59', //最大日期
            istime: true,
            istoday: false,
            choose: function (datas) {
                end.min = datas; //开始日选好后，重置结束日的最小日期
                end.start = datas //将结束日的初始值设定为开始日
            }
        };
        var end = {
            elem: '#end',
            format: 'YYYY-MM-DD hh:mm:ss',
            min: laydate.now(),
            max: '2099-06-16 23:59:59',
            istime: true,
            istoday: false,
            choose: function (datas) {
                start.max = datas; //结束日选好后，重置开始日的最大日期
            }
        };
        laydate(start);
        laydate(end);
        //查看订单
        $('.check_order').click(function(){
            //var url = 'foradmin/order/details';//前端模板测试
            var url = '/foradmin/order/' + $(this).data('id');//前端正式
            var title = '订单详情';
            open_page(url, title);//打开新页面
            /*$(window.parent.document).find('.J_menuTabs .page-tabs-content a').removeClass('active');
            $(window.parent.document).find('.J_menuTabs .page-tabs-content').append('<a href="javascript:;" class="J_menuTab active" data-id="'+url+'">'+title+' <i class="fa fa-times-circle"></i></a>');
            // 添加选项卡对应的iframe
            var str1 = '<iframe class="J_iframe" name="iframe' + $(this).attr('data-id') + '" width="100%" height="100%" src="' + url + '" frameborder="0" data-id="' + url + '" seamless></iframe>';
            $(window.parent.document).find('.J_mainContent').find('iframe.J_iframe').hide().parents('.J_mainContent').append(str1);*/
        })

        //取消订单
        $('.cancel_order').click(function(){
            var order_id = $(this).attr('data-id');
            var url = cancel_order.replace('{id}', order_id);
            layer.confirm('是否取消订单？', {
                btn: ['确认', '取消'] //可以无限个按钮
            }, function (index) {
                $.ajax({
                    url: url,
                    type: 'PUT',
                    dataType: 'json',
                    data: {'type': 'order_cancel'},
                    success: function (data) {
                        if (0 == data.code) {
                            layer.alert(data.message, {
                                icon: 1
                            }, function () {
                                location.reload();
                            });
                        } else {
                            layer.alert(data.message, {
                                icon: 2
                            });
                        }
                    },
                });
            }, function (index, layero) {
                layer.close(index);
            });
        })
    </script>
@endsection